<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/zy_common.css"/>
    <link rel="stylesheet" href="../css/mobiscroll.jquery.min.css" />
    <link rel="stylesheet" href="../css/zy_base.css"/>
    <script src="../../../千帕售货柜/h6/app.js"></script>
</head>
<body>
    <div class="bw">
        <div class="h100 lh100 font15 col3 plr24 bdb"><span>设备类型：</span><span>纸巾机</span></div>
        <div class="h100 lh100 font15 col3 plr24 bdb"><span>设备编号：</span><span id="macno">45646454</span></div>
        <div class="h100 lh100 font15 col3 plr24 bdb"><span>设备单价：</span><span id="price">￥10.00</span></div>
        <div class="h100 lh100 font15 col3 plr24 bdb"><span>设备IMEI：</span><span id="imei">26.00</span></div>
    </div>
    <div class="font15 col9 plr24 h100 lh100">其他信息</div>
    <div class="bw font15">
        <div class="flex_sb plr24 bdb">
            <span class="col3">设备地址</span>
            <input type="text" placeholder="请输入" class="h100 col9 font15 tae" id="addr">
        </div>
        <div class="flex_sb plr24 bdb">
            <span class="col3">设备库存</span>
            <input type="number" placeholder="请输入" class="h100 col9 font15 tae" oninput="this.value = this.value.replace(/\D/g,'')" id="num">
        </div>
        <div class="flex_sb plr24 bdb">
            <span class="col3">代理人</span>
            <input type="text"  readonly class="h100 col9 font15 tae" id="agent">
        </div>
        <div class="flex_sb plr24 bdb">
            <span class="col3">运维人员</span>
            <em class="flex_a">
                <input type="text" placeholder="请选择" class="h100 col9 font15 tae mr20" readonly id="operations">
                <img src="../img/arrow_right.png" class="arrow_r" alt="">
            </em>
        </div>
        <div class="flex_sb plr24 bdb">
            <span class="col3">运维热线</span>
            <input type="tel" placeholder="请输入" class="h100 col9 font15 tae" oninput="this.value = this.value.replace(/\D/g,'')" id="phone">
        </div>
    </div>
    <div class="confirm" style="margin-top: .6rem"></div>
</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script type="text/javascript" src="../js/mobiscroll.jquery.min.js"></script>
<script>

    var arrObj=[];
    var opsId='';
    var onOff=0;
    var deviceId;
    $('#agent').val(getLocalData('fd_parentName'));//代理人名字
    $(function(){
        $('#macno').text(getUrlParam('macno'));
        $('#imei').text(getUrlParam('imei'));
        $('#price').text('￥'+getUrlParam('price'));
        if(getUrlParam('type')==1){//编辑
            $('title').text('编辑');
            $('.confirm').text('保存');
            dlctipbox.loading('请稍后');
            dlc_request('/api/device/getDeviceList',{id:getLocalData('fd_id'),type:2,deviceNo:getUrlParam('macno')},function (res) {
                dlctipbox.clear();
                console.log(res);
                if(res.code==1){
                    var res = res.data[0];
                    $('#addr').val(res.addressDetail);
                    $('#num').val(res.inventory);
                    $('#operations').val(res.opsName);
                    $('#phone').val(res.opsPhone);
                    opsId=res.opsId;
                    deviceId=res.deviceId;
                }else{
                    dlctipbox.show(res.msg);
                }
            })
        }else{//绑定设备
            $('title').text('绑定设备');
            $('.confirm').text('绑定设备');
        }

        //确定
        $('.confirm').click(function () {
            var addr = $('#addr').val();
            var num = $('#num').val();
//            var operations = $('#operations').val();
            var phone = $('#phone').val();
            if(isNull(addr)){
                dlctipbox.show('请输入设备地址');
            }else if(isNull(num)){
                dlctipbox.show('请输入设备库存');
            }else if(isNull(opsId)){
                dlctipbox.show('请选择运维人员');
            }else if(isNull(phone)){
                dlctipbox.show('请输入运维热线');
            }else if(!checkMobileAndTel(phone)){
                dlctipbox.show('运维热线有误');
            }else{
                if(onOff)return false;
                onOff=1;
                dlctipbox.loading('请稍后');
                if(getUrlParam('type')==1){//编辑
                    var data={
                        deviceId:deviceId,
                        deviceNo:getUrlParam('macno'),
                        imei:getUrlParam('imei'),
                        opsId:opsId,
                        goodsPrice:getUrlParam('price'),
                        addressDetail:addr,
                        inventory:num,
                        opsPhone:phone
                    };
                    dlc_request('/api/device/eidtSave',data,function (res) {
                        dlctipbox.clear();
                        console.log(res);
                        if(res.code==1){
                            dlctipbox.alert('保存成功',function (flag) {
                                if(flag==1){
                                    history.go(-1);
                                }
                            })
                        }else{
                            onOff=0;
                            dlctipbox.show(res.msg);
                        }
                    })
                }else{//绑定设备
                    var data={
                        agentId:getLocalData('fd_parentId'),
                        deviceNo:getUrlParam('macno'),
                        deviceImei:getUrlParam('imei'),
                        opsId:opsId,
                        opsPhone:phone,
                        addr:addr,
                        inventory:num
                    };
                    dlc_request('/api/relation/addRelation',data,function (res) {
                        dlctipbox.clear();
                        console.log(res);
                        if(res.code==1){
                            dlctipbox.alert('绑定成功',function (flag) {
                                if(flag==1){
                                    history.go(-1);
                                }
                            })
                        }else{
                            onOff=0;
                            dlctipbox.show(res.msg);
                        }
                    })
                }

            }

        })
    });

    dlc_request('/api/apiAgent/getOpsList',{agentId:getLocalData('fd_parentId')},function (res) {
        console.log(res);
        if(res.code==1){
            res.data.forEach(function (item,index) {
                var obj = {};
                obj.value=item.id;
                obj.display=item.name;
                arrObj.push(obj);
            })
            //选择运维人员
            $('#operations').mobiscroll().scroller({
                theme: 'mobiscroll',
                display: 'bottom',
                cancelText: '',
                setText: '',
                closeOnOverlayTap: false,
                showLabel: true,
                lang: 'zh',
                wheels: [
                    [{
                        label: '',
                        data: arrObj
                    }]
                ],
                onBeforeClose: function (event, inst) {
                    var button=event.button;
                    if (button !== 'cancel') {
                        console.log(event.valueText);
                        opsId=event.valueText;
                        arrObj.forEach(function (item,index) {
                            if(opsId==item.value){
                                $('#operations').val(item.display);
                            }
                        })

                    }
                },
                headerText: function (valueText) {
                    return "<div class='headerText'><a class='l' onclick='cancle1()'>取消</a>请选择<a class='r' onclick='confirm1();'>确定</a></div><div class='notnotice'></div>";
                }
            });
        }else{
            console.log(res.msg);
        }
    })




    function cancle1() {
        $('#operations').mobiscroll('cancel');
    }

    function confirm1() {
        $('#operations').mobiscroll('hide');
    }
</script>